import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author wonghiu
 * @Date 2021/8/7 15:21
 * @Version 1.0.1
 */
public class qianxin {
    public static void main(String[] args) {
        System.out.println(new Solution().TeamNums(new int[]{1,5,3,2,4}));
    }

    static class Solution {
        /**
         * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
         *
         *
         * @param height int整型一维数组 舞蹈员身高的一维数组
         * @return int整型
         */
//        List<Integer> temp = new ArrayList<>();
//    List<List<Integer>> ans = new ArrayList<>();
        int ansCount = 0;
        int tempSize = 0;
        int tempSize2 = 0;
        public int TeamNums (int[] height) {
            for (int i = 0; i <height.length ; i++) {
//                temp = new ArrayList<>();
//                temp.add(height[i]);
                tempSize=1;
                dfs1(height,i+1,height.length-1,height[i]);
                tempSize2 = 1;
                dfs2(height,i+1,height.length-1,height[i]);
            }

            return ansCount;
        }

        private void dfs1(int[] height, int start, int end, int target) {
//            System.out.println(temp);
//            System.out.println(tempSize);

            if (tempSize==3){
                ansCount++;
                return;
            }
            if (start>end){
                return;
            }
            for (int i = start; i <= end; i++) {
                if (height[i]>target){
//                    temp.add(height[i]);
                    tempSize++;
                    dfs1(height,i+1,end,height[i]);
                    tempSize--;
//                    temp.remove(temp.size()-1);
                }
            }
        }
        private void dfs2(int[] height, int start, int end, int target) {
//            System.out.println(temp);
//            System.out.println(tempSize2);

            if (tempSize2==3){
                ansCount++;
                return;
            }
            if (start>end){
                return;
            }
            for (int i = start; i <= end; i++) {
                if (height[i]<target){
//                    temp.add(height[i]);
                    tempSize2++;
                    dfs2(height,i+1,end,height[i]);
                    tempSize2--;
//                    temp.remove(temp.size()-1);
                }
            }
        }
    }
}
